home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 4.8 KB | 181 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // CreatorAndBundle.cp
- // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
- // CreatorAndBundle -- post process application for bundle resource and shared bit
- //----------------------------------------------------------------------------------------
-
- // MacApp
-
- #ifndef __UCPLUSTOOL__
- #include <UCPlusTool.h>
- #endif
-
- // ToolBox
-
- #ifndef __FINDER__
- #include <Finder.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
-
- class TCreatorAndBundleTool : public TCPlusTool
- {
- MA_DECLARE_CLASS;
-
- public:
- TCreatorAndBundleTool(); // constructor
-
- virtual ~TCreatorAndBundleTool();
- // Destructor
-
- void ICreatorAndBundleTool(int argc, char** argv);
-
- virtual void DoProcessFileArg(const CStr255& arg); // override
-
- virtual void DoToolAction(); // override
-
- void DoAutoMagicCreatorAndBundleAndSharedBit();
-
- protected:
- CStr255 fResFileName;
-
- };
-
-
- TCreatorAndBundleTool* gCreatorAndBundleTool; // The tool
-
-
- //========================================================================================
- // CLASS TCreatorAndBundleTool
- //========================================================================================
- #undef Inherited
- #define Inherited TCPlusTool
-
- #pragma segment TRes
- MA_DEFINE_CLASS_M1(TCreatorAndBundleTool, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCreatorAndBundleTool constructor
- //----------------------------------------------------------------------------------------
- #pragma segment TRes
-
- TCreatorAndBundleTool::TCreatorAndBundleTool()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCreatorAndBundleTool destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TCreatorAndBundleTool::~TCreatorAndBundleTool()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCreatorAndBundleTool::ICreatorAndBundleTool:
- //----------------------------------------------------------------------------------------
- #pragma segment TInit
-
- void TCreatorAndBundleTool::ICreatorAndBundleTool(int argc, char** argv)
- {
- this->ICPlusTool(argc, argv);
- }
-
- //----------------------------------------------------------------------------------------
- // TCreatorAndBundleTool::DoProcessFileArg:
- //----------------------------------------------------------------------------------------
- #pragma segment TInit
-
- void TCreatorAndBundleTool::DoProcessFileArg(const CStr255& arg)
- {
- if (fResFileName.Length() > 0)
- this->Stop("Sorry… only smart enough to process one file");
- else
- fResFileName = arg;
- }
-
- //----------------------------------------------------------------------------------------
- // TCreatorAndBundleTool::DoAutoMagicCreatorAndBundleAndSharedBit:
- //----------------------------------------------------------------------------------------
- #pragma segment TRes
-
- typedef OSType** OSTypeHandle;
-
- void TCreatorAndBundleTool::DoAutoMagicCreatorAndBundleAndSharedBit()
- {
- CStr255 aName;
- FInfo theFInfo;
- OSTypeHandle theBundle;
-
- aName = fResFileName;
- FailOSErr(GetFInfo(aName, 0, &theFInfo));
- theBundle = (OSTypeHandle)Get1IndResource('BNDL', 1);
- if (theBundle != NULL)
- {
- theFInfo.fdCreator = **theBundle;
- theFInfo.fdFlags |= kHasBundle;
- }
- else
- {
- theFInfo.fdCreator = '????';
- theFInfo.fdFlags &= (~kHasBundle);
- }
- theFInfo.fdFlags |= kIsShared; // by default MacApp apps can be shared cause they don't write back to themselves.
-
- FailOSErr(SetFInfo(aName, 0, &theFInfo));
- }
-
- //----------------------------------------------------------------------------------------
- // TCreatorAndBundleTool::DoToolAction:
- //----------------------------------------------------------------------------------------
- #pragma segment TRes
-
- void TCreatorAndBundleTool::DoToolAction()
- {
- CStr255 aName;
- short ref;
-
- if (fResFileName.IsEmpty())
- this->Stop("No filename specified");
-
- aName = fResFileName;
-
- SetResLoad(FALSE); // avoid preloads
- ref = OpenResFile(aName);
- SetResLoad(TRUE);
- if (ref == -1)
- FailResError();
-
- this->DoAutoMagicCreatorAndBundleAndSharedBit();
-
- CloseResFile(ref);
- FailResError();
- }
-
- //----------------------------------------------------------------------------------------
- // main:
- //----------------------------------------------------------------------------------------
- #pragma segment TRes
-
- void main(int argc, char** argv)
- {
- InitUCPlusTool();
-
- gCreatorAndBundleTool = new TCreatorAndBundleTool;
- gCreatorAndBundleTool->ICreatorAndBundleTool(argc,argv);
- gCreatorAndBundleTool->Run();
- }
-
- //----------------------------------------------------------------------------------------
- // End of CreatorAndBundle.cp
-
- #pragma segment Inline
-